package hibernate;

/**
 *
 * @author Igor Kovb
 */
public class Product extends DBEntity {

    private String description;
    private boolean common;
    private ProductCategory prodCategory;

    Product() {
    }

    /**
     * @return the description
     */
    public String getDescription() {
        return description;
    }

    /**
     * @param description the description to set
     */
    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * @return the prodCategory
     */
    public ProductCategory getProdCategory() {
        return prodCategory;
    }

    /**
     * @param prodCategory the prodCategory to set
     */
    public void setProdCategory(ProductCategory prodCategory) {
        this.prodCategory = prodCategory;
    }

    /**
     * @return the isCommon
     */
    public boolean isCommon() {
        return common;
    }

    /**
     * @param isCommon the isCommon to set
     */
    public void setCommon(boolean common) {
        this.common = common;
    }

    /**
     * This method does not care about the id of product classes
     * I realize this is a little stupid, however, I saw in Bussiness logic
     * it product comparison was used without id comparison, so I made 
     * equals support without id comparison (however I dont think it is normal)
     * but the time is running...
     * @param p
     * @return 
     */
    public boolean equalsByDescription(Product p) {
        boolean res = false;
        if (this.getDescription().equals(p.getDescription())) {
            res = true;
        }
        return res;
    }

    @Override
    public boolean equals(Object o) {
        boolean res = false;
        if (o instanceof Product) {
            Product p = (Product) o;
            res = this.equalsByDescription(p);
        }
        return res;
    }
}
